using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CAnswerManage
	{
		public static CAnswer CreateAnswer()
       {      
           return   new CAnswer();
       }
	   
	   public static CAnswer Save(CAnswer answer)
	   {
			try
           {
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddAnswer", answer.ID, answer.questionID, answer.answerContent, answer.answerTime);
             
				if(0 == num)
                   return null;
                return answer;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CAnswer answer)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveAnswer", answer.ID, answer.questionID, answer.answerContent, answer.answerTime);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CAnswer answer)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveAnswer", answer.ID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CAnswer GetAnswer(String ID)
	   {

           SqlDataReader reader = BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetAnswer", ID);
		   
           try
           {                       
               if (reader.Read())
               { 
					CAnswer answer = new CAnswer();
					answer.questionID = reader["questionID"].ToString();
					answer.answerContent = reader["answerContent"].ToString();
					//answer.answerTime = reader["answerTime"];
				
					return answer;
               }
               return null;
           }
           catch (Exception e)
           {
               return null;
           }
           finally
		   {
                reader.Close();
	       }
	   }
	   
	}
}